define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'ter.technician_review/index',
        add_url: 'ter.technician_review/add',
        edit_url: 'ter.technician_review/edit',
        delete_url: 'ter.technician_review/delete',
        export_url: 'ter.technician_review/export',
        modify_url: 'ter.technician_review/modify',
        adopt_url: 'ter.technician_review/adopt_url',
        reject_url: 'ter.technician_review/reject_url',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh'],
                cols: [[
                    {field: 'username', minWidth: 80, title: '姓名'},
                    {field: 'img', minWidth: 80, title: '头像', search: false, templet: ea.table.image}, 
                    {field: 'phone', minWidth: 80, title: '手机号'},
                    {field: 'age', minWidth: 80, title: '年龄',search: false},
                    {field: 'sex', title: '性别',selectList: {1: '男',2: '女'}},
                    {field: 'status', title: '审核状态',selectList: {0: '待审核',1: '审核通过',2: '审核驳回'}},
                    {field: 'rejection', minWidth: 80, title: '拒绝原因',search: false},
                    {field: 'create_time', title: '申请时间',search: false},
                    // {title: '操作', templet: ea.table.tool,operat:[
                    //     [
                    //         {
                    //             text: '通过',
                    //             title: '确定通过吗？',
                    //             url: init.adopt_url,
                    //             method: 'request',
                    //             auth: 'edit',
                    //             class: 'layui-btn layui-btn-xs layui-btn-success'
                    //         }
                    //    ],
                    //    [
                    //         {
                    //             text: '驳回',
                    //             url: init.reject_url,
                    //             method: 'open',
                    //             auth: 'edit',
                    //             class: 'layui-btn layui-btn-xs layui-btn-danger'
                    //         },
                    //     ]
                    // ]
                    // },
                    {title: '操作', templet: function (d) {
                        if(d.status == 1 || d.status == 2){
                            return '<button class="layui-btn layui-btn-normal layui-btn-sm layui-btn-disabled" >通过</button>  <button class="layui-btn layui-btn-normal layui-btn-sm layui-btn-disabled" >驳回</button>';
                        }else{
                            return '<button class="layui-btn layui-btn-xs layui-btn-success" data-request="ter.technician_review/adopt_url?id='+d.id+'"  data-title="确定通过吗？" >通过</button>' +
                                '<button class="layui-btn layui-btn-xs layui-btn-danger" data-open="ter.technician_review/reject_url?id='+d.id+'"  data-title="驳回" >驳回</button>'
                        }
                        }
                    },
                ]],
            });
            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        reject_url: function () {
            ea.listen();
        },
    };
    return Controller;
});